/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Presentacion;

import LibreriaServer.LServer;
import LibreriaServer.tread;
import MailCliente.MailCliente;
import Message.Mensaje;
import com.sun.istack.internal.logging.Logger;
import java.awt.Image;
import java.io.File;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.logging.Level;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.filechooser.FileNameExtensionFilter;
import mailserver.MailServer1;
import mailserver.Server;

/**
 *
 * @author Windows xp
 */
public class IUMensajes extends javax.swing.JFrame {

    private MailCliente user;
    private MailServer1 servidor;
    private JFileChooser direccion;
    private Thread run;


    /**
     * Creates new form IUMensajes
     */
    public IUMensajes() {
        initComponents();
        user = null;
        direccion = new JFileChooser();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        nameUser = new javax.swing.JLabel();
        Noleidos = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        msjLeidos = new javax.swing.JLabel();
        resultadomsjleidos = new javax.swing.JLabel();
        jLabelfoto = new javax.swing.JLabel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel3 = new javax.swing.JPanel();
        ListaMailServer = new javax.swing.JComboBox();
        destino = new javax.swing.JTextField();
        asunto = new javax.swing.JTextField();
        mensaje = new javax.swing.JTextField();
        enviar = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tablamensajesEnviados = new javax.swing.JTable();
        jPanel2 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        siguiente = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablamensajes = new javax.swing.JTable();
        Actualisar = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        dire = new javax.swing.JTextField();
        salir = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        nameUser.setFont(new java.awt.Font("Tempus Sans ITC", 1, 14)); // NOI18N
        nameUser.setText("jLabel4");

        Noleidos.setFont(new java.awt.Font("Tempus Sans ITC", 1, 14)); // NOI18N
        Noleidos.setText("0");

        jLabel1.setFont(new java.awt.Font("Tempus Sans ITC", 1, 14)); // NOI18N
        jLabel1.setText("Mensaje no Leidos");

        msjLeidos.setFont(new java.awt.Font("Tempus Sans ITC", 1, 14)); // NOI18N
        msjLeidos.setText("Mensajes Leidos");

        resultadomsjleidos.setFont(new java.awt.Font("Tempus Sans ITC", 1, 14)); // NOI18N
        resultadomsjleidos.setText("0");

        jLabelfoto.setText("Foto");
        jLabelfoto.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jLabelfoto.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabelfotoMouseClicked(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabelfoto, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 109, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(nameUser, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 151, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel1)
                    .add(msjLeidos))
                .add(29, 29, 29)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(Noleidos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 39, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(resultadomsjleidos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 67, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(2, 2, 2))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(Noleidos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 14, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(resultadomsjleidos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 14, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel1)
                            .add(nameUser))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(msjLeidos)))
                .add(56, 56, 56))
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabelfoto, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 94, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        ListaMailServer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ListaMailServerActionPerformed(evt);
            }
        });

        enviar.setText("Enviar ");
        enviar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                enviarActionPerformed(evt);
            }
        });

        jLabel5.setText("Correo Electronico");

        jLabel6.setText("Para:");

        jLabel7.setText("Asunto:");

        jLabel8.setText("Mensaje:");

        tablamensajesEnviados.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Para:", "Asunto:", "Mensaje:"
            }
        ));
        tablamensajesEnviados.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tablamensajesEnviadosMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(tablamensajesEnviados);

        org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel3Layout.createSequentialGroup()
                        .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel5)
                            .add(jLabel6)
                            .add(jLabel7)
                            .add(jLabel8))
                        .add(40, 40, 40)
                        .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(ListaMailServer, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 133, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(asunto, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE)
                            .add(destino)
                            .add(mensaje))
                        .add(29, 29, 29)
                        .add(enviar)
                        .add(0, 74, Short.MAX_VALUE))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 497, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel3Layout.createSequentialGroup()
                        .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(ListaMailServer, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(enviar))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(destino, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(asunto, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jPanel3Layout.createSequentialGroup()
                        .add(jLabel5)
                        .add(23, 23, 23)
                        .add(jLabel6)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jLabel7)))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel8)
                    .add(mensaje, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 74, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 127, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(79, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Enviar Mensajes", jPanel3);

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel3.setText("Siguiente Mensaje");

        siguiente.setText(">>>");
        siguiente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                siguienteActionPerformed(evt);
            }
        });

        tablamensajes.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "De:", "Asunto:", "Mensaje:"
            }
        ));
        tablamensajes.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tablamensajesMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tablamensajes);

        Actualisar.setText("actualizar");
        Actualisar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ActualisarActionPerformed(evt);
            }
        });

        jLabel2.setText("Ubicacion del archivo donde fue guardado");

        dire.setText("jTextField1");
        dire.setEnabled(false);

        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .add(45, 45, 45)
                .add(jLabel3)
                .add(31, 31, 31)
                .add(siguiente)
                .add(140, 140, 140)
                .add(Actualisar)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .add(jPanel2Layout.createSequentialGroup()
                .add(30, 30, 30)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(dire, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 248, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel2))
                .add(0, 239, Short.MAX_VALUE))
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 483, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(siguiente)
                    .add(jLabel3)
                    .add(Actualisar))
                .add(18, 18, 18)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 173, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(60, 60, 60)
                .add(jLabel2)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(dire, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(65, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Mensajes Recibidos", jPanel2);

        salir.setText("Salir");
        salir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salirActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 526, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(103, Short.MAX_VALUE))
                    .add(layout.createSequentialGroup()
                        .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .add(18, 18, 18)
                        .add(salir)
                        .add(19, 19, 19))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(salir)
                    .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(29, 29, 29)
                .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 427, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void ListaMailServerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ListaMailServerActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ListaMailServerActionPerformed

    private void enviarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enviarActionPerformed
        try {
            // TODO add your handling code here
            if (!destino.getText().equals("")) {
            String datoDestino = (String) ListaMailServer.getSelectedItem();
            datoDestino = destino.getText() + LServer.token + datoDestino;
            Mensaje mensaje1 = new Mensaje(user.getName(), datoDestino, asunto.getText(), mensaje.getText());

            MailServer1 mailservidor = new MailServer1(ListaMailServer.getSelectedItem().toString());

            mailservidor.post(mensaje1);
            mensaje1.Sender(destino.getText().toString());
            user.bandejadMessage(mensaje1);
            LimpiarDatos();
            LServer.mostrarmensaje(user.getListaMensajesEnviados(), tablamensajesEnviados);
            
            }
            else {
                 JOptionPane.showMessageDialog(rootPane, " Favor ingresar un destinatario  :) ");      
            }
        } catch (Exception ex) {
            java.util.logging.Logger.getLogger(IUMensajes.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_enviarActionPerformed

    private void siguienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_siguienteActionPerformed
        // TODO add your handling code here:

        Mensaje mensaje = (Mensaje) servidor.getNextMessage(user.getName());
        if (mensaje != null) {
            user.sendMessage(mensaje);
            //            ActualisarActionPerformed(evt);
            //        LServer.mostrarmensaje(user.getListaMensajesCliente(), tablamensajes);
        }
        ActualisarActionPerformed(evt);
    }//GEN-LAST:event_siguienteActionPerformed

    private void tablamensajesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablamensajesMouseClicked

        direccion.setAcceptAllFileFilterUsed(false);
        if (direccion.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
            ArrayList<Mensaje> mensajes = user.getListaMensajesCliente();
            int punto = tablamensajes.getSelectedRow();
            Mensaje mensajeValido;
            mensajeValido = mensajes.get(punto);
            String dir = direccion.getSelectedFile().toString();
            dire.setText(dir);
            LServer.guardarMensaje(dir, mensajeValido);

        }

    }//GEN-LAST:event_tablamensajesMouseClicked

    private void ActualisarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ActualisarActionPerformed
        // TODO add your handling code here:
        LServer.mostrarmensaje(user.getListaMensajesCliente(), tablamensajes);
        int mensajesNoLeidos = servidor.getMessagesWaitting(user.getName());
        Noleidos.setText("" + mensajesNoLeidos);
        ArrayList<Mensaje> mensajesLeidos = user.getListaMensajesCliente();
        int cantidadElementos = mensajesLeidos.size();
        resultadomsjleidos.setText("" + cantidadElementos);
    }//GEN-LAST:event_ActualisarActionPerformed

    private void salirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salirActionPerformed
        // TODO add your handling code here:

        run.stop();
        run.interrupt();
        run = null;

        this.dispose();

    }//GEN-LAST:event_salirActionPerformed

    private void tablamensajesEnviadosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablamensajesEnviadosMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_tablamensajesEnviadosMouseClicked

    private void jLabelfotoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabelfotoMouseClicked
        // TODO add your handling code here:

        JFileChooser selector = new JFileChooser();
        FileNameExtensionFilter filtroImagen = new FileNameExtensionFilter("JPG, PNG & GIF", "jpg", "png", "gif");
        selector.setFileFilter(filtroImagen);
        int r = selector.showOpenDialog(null);
        if (r == JFileChooser.APPROVE_OPTION) {
            try {
                ImageIcon img = new ImageIcon(selector.getSelectedFile().toURL());
                Icon icono = new ImageIcon(img.getImage().getScaledInstance(jLabelfoto.getWidth(), jLabelfoto.getHeight(),Image.SCALE_DEFAULT ));
                jLabelfoto.setIcon(icono);
                this.repaint();
                user.setImg(img);
                user.guardar();

            } catch (MalformedURLException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        }

    }//GEN-LAST:event_jLabelfotoMouseClicked

    public void addClient(MailCliente usuario) {
          user = usuario;
        Server server = new Server();
        String dato = user.getName();
        dato = LServer.UsuarioDato(dato);
        nameUser.setText(dato);
        jLabelfoto.setIcon(user.getImg());
        ArrayList<Mensaje> mensaje = user.getListaMensajesCliente();

        LServer.mostrarmensaje(mensaje, tablamensajes);

        resultadomsjleidos.setText("" + user.getListaMensajesCliente().size());
        servidor = (MailServer1) user.getServer();
        Noleidos.setText("" + servidor.getMessagesWaitting(user.getName()));
        LServer.mostrarCombox(ListaMailServer, server.getListaServer());

        tread hilo = new tread(servidor, 9000, user.getName(), user);
        run = new Thread(hilo);
        run.start();


    }

    private void LimpiarDatos() {
        destino.setText("");
        asunto.setText("");
        mensaje.setText("");
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(IUMensajes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(IUMensajes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(IUMensajes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(IUMensajes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new IUMensajes().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Actualisar;
    private javax.swing.JComboBox ListaMailServer;
    private javax.swing.JLabel Noleidos;
    private javax.swing.JTextField asunto;
    private javax.swing.JTextField destino;
    private javax.swing.JTextField dire;
    private javax.swing.JButton enviar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabelfoto;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField mensaje;
    private javax.swing.JLabel msjLeidos;
    private javax.swing.JLabel nameUser;
    private javax.swing.JLabel resultadomsjleidos;
    private javax.swing.JButton salir;
    private javax.swing.JButton siguiente;
    private javax.swing.JTable tablamensajes;
    private javax.swing.JTable tablamensajesEnviados;
    // End of variables declaration//GEN-END:variables
}
